package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.UserVocAISituationDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserVocAISituationCommand;
import com.cskaoyan.wordmemorize.service.AIReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/voc/ai-read")
public class AdminAIReadController {
    @Autowired
    AIReadService aiReadService;
    @SaAdminCheckPermission("admin:ai-read:situation:add")
    @PostMapping("situation")
    public Result addAIReadSituation(@RequestBody UserVocAISituationCommand  command) {
        aiReadService.addAISituation( command);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:ai-read:situation:update")
    @PutMapping("situation")
    public Result updateAIReadSituation(@RequestBody UserVocAISituationCommand  command) {
        aiReadService.updateAISituation(command);
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:ai-read:situation:batchdelete")
    @DeleteMapping("situation")
    public Result deleteAIReadSituation(@RequestBody BatchDeleteCommand  command) {
        // 将List<String>转换为List<Long>
        List<Long> longIds = command.getIds().stream()
                .map(Long::valueOf)
                .collect(Collectors.toList());

        aiReadService.batchDeleteAISituationOption(longIds); // 传递转换后的Long列表
        return Result.ok();
    }
    @SaAdminCheckPermission("admin:ai-read:situation:search")
    @GetMapping("situation/list")
    public Result<PageDTO<UserVocAISituationDTO>> getAIReadSituationList(PageRequest pageRequest) {
        PageDTO<UserVocAISituationDTO> list = aiReadService.getAISituationList(pageRequest);
        return Result.ok(list);
    }
    @SaAdminCheckPermission("admin:ai-read:situation:delete")
    @DeleteMapping("situation/{id}")
    public Result deleteAIReadSituation(@PathVariable Long id)
    {
        aiReadService.deleteAISituation(id);
        return Result.ok();
    }
    @DeleteMapping("option/{id}")
    public Result deleteAIReadSituationOption(@PathVariable Long id)
    {
        aiReadService.deleteAISituationOption(id);
        return Result.ok();
    }

}
